<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <dataBrowserForm ref="realForm" @ok="submitCallback" :disabled="disableSubmit"></dataBrowserForm>
  </j-modal>
</template>
  
  <script>
import dataBrowserForm from './dataBrowserForm'
import { getAction } from '@api/manage'
export default {
  name: 'ChatVectorFileCabinetModal',
  components: {
    dataBrowserForm,
  },
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      url: {
        queryById: '/ChatVectorFileCabinet/chatVectorFileCabinet/queryById',
      },
    }
  },
  methods: {
    add(index, model) {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.add(index, model)
      })
    },
    edit(record) {
      let params = {
        id: record.id,
      }
      let options = {}
      getAction(this.url.queryById, params)
        .then((res) => {
          if (res.code == 200) {
            options = res.result
          }
        })
        .finally(() => {
          this.visible = true
          this.$nextTick(() => {
            this.$refs.realForm.edit(options)
          })
        })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      this.$refs.realForm.submitForm()
    },
    submitCallback() {
      this.$emit('ok')
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>